let collegeOption = '--请选择--';
let page = 1;
let startData = 0;
let sumPage;
let seach = '--空白--';
let role = 2;
$(function() {
			pageLoad();
			listData();
		})
function pageLoad(){
	var sys_ids = '#fyXq';
			var select_isBool = 'true';
			var select_type = 'SUBJECT';
			selectHtml(sys_ids, select_isBool, select_type);
}
// 学院改变事件
function getFyDhListByFyXqCodes() {
	$("#fyXq").unbind();
	startData = 0;
	$("#fyZldz").val("");
	seach = '--空白--';
	let options = $("#fyXq option:selected");
	// alert(options.val())
	page = 1;
	collegeOption = options.text();
	listData();
}

// 列表数据
function listData() {
	$(".table").unbind();
	let infoData = {
		'start' : startData,
		'collegeOption' : collegeOption,
		'search':seach,
		'role':role
	}
	let infoDatas = dataAjax('/user/dataInfo','post', infoData, 'json');
	// alert(JSON.stringify(infoDatas[0].data.data));
	let tableHtml = '<tr>\n'
			+ '<th width="30"><input type="checkbox" id="all" name = "check" onclick="selectOrClearAllCheckbox(this);" />\n'
			+ '</th>\n' + '<th>姓名</th>\n' + '<th>性别</th>\n' + '<th>证件号码</th>\n'
			+ '<th>学历</th>\n' + '<th>出生日期</th>\n' + '<th>电话</th>\n'
			+ '<th>邮箱</th>\n' + '<th>研究方向</th>\n'+'<th>职工号</th>'+'<th>权限</th>'+'<th>角色</th>'
			+ '<th>操作</th>\n' + '</tr>\n';
	// 数据长度
	let index = infoDatas[0].data.data.length;
	let indexData = infoDatas[0].data.data;
	for (var i = 0; i < index; i++) {
		tableHtml += '<tr>\n'
				+ '<td><input type="checkbox" name="IDCheck" value="'
				+ indexData[i].user_id + '" class="acb" onclick="selectCheckbox();"/>\n' + '</td>\n'
				+ '<td>' + indexData[i].name + '</td>\n' + '<td>'
				+ indexData[i].sex + '</td>\n' + '<td>'
				+ indexData[i].numberID + '</td>\n' + '<td>'
				+ indexData[i].gradation + '</td>\n' + '<td>'
				+ indexData[i].birthday + '</td>\n' + '<td>'
				+ indexData[i].tel + '</td>\n' + '<td>'
				+ indexData[i].email + '</td>\n' + '<td>'
				+ indexData[i].direction + '</td>\n' + '<td>'
			+ indexData[i].number + '</td>\n' + '<td>'
			+ indexData[i].limits + '</td>\n' + '<td>'
			+ indexData[i].role + '</td>\n' + '<td>'
				+ '<a href="teacher_edit.html?fyID=' + indexData[i].user_id
				+ '" class="edit">编辑</a>\n' + '<a href="javascript:del('
				+ indexData[i].user_id +');">删除</a></td>\n' + '</tr>\n';
	}
	$(".table").html(tableHtml);
	var sum = parseInt(infoDatas[0].data.sum);
	$("#ui_txt").html(sum);
	if (0 == sum) {
		page = 0;
		$("#jumpNumTxt").attr("value",page);
		$("#ui_txtPage").html(page + '\n/\n' + Math.ceil(sum / 10));
	} else {
		$("#jumpNumTxt").attr("value",page);
		$("#ui_txtPage").html(page + '\n/\n' + Math.ceil(sum / 10));
	}
	sumPage = Math.ceil(sum / 10);
	
	mouse();
}
// 下一页
function nextNormalPage(dom) {
	if (page < sumPage) {
		$(dom).unbind();
		startData = (page) * 10;
		page += 1;
		listData();
	} else {
		alert("已经是尾页！");
	}
}
// 上一页
function perviousNormalPage(dom) {
	if (page > 1) {
		$(dom).unbind();
		page -= 1;
		startData = (page - 1) * 10;
		listData();
	} else {
		alert("已经是首页！");
	}

}
// 首页
function oneNormalPage(dom) {
	$(dom).unbind();
	startData = 0;
	page = 1;
	listData();
}
// 尾页
function endNormalPages(dom) {
	$(dom).unbind();
	page = sumPage;
	startData = (page-1) * 10;
	listData();
}
// 跳转
function skipPage(dom) {
	$(dom).unbind();
	var skipValue = $("#jumpNumTxt").val();
	var skip = /^[0-9]+$/;
	// alert(skipValue);
	if ("" == skipValue) {
		alert("请输入需要跳转的页码!");
		$("#jumpNumTxt").attr("value",page);
	} else {
		if (skip.test(skipValue)) {
			var pageValue = parseInt(skipValue);
			if (pageValue >= 1 && pageValue <= sumPage) {
				page = pageValue;
				startData = (page - 1) * 10;
				listData();
			} else {
				alert("没有该页码！请重新输入！");
				$("#jumpNumTxt").attr("value",page);
			}
		} else {
			alert("输入错误！页码只能是数字！");
			$("#jumpNumTxt").attr("value",page);
		}
	}
}
/** 模糊查询用户  **/
function search(dom){
	$(dom).unbind();
	$(".table").unbind();
    seach = $("#fyZldz").val();
    if('' == seach){
    	seach = '--空白--';
    	alert("请输入需要查询得数据");
    }else{
    	collegeOption = '--请选择--';
		pageLoad();
		page = 1;
		startData = 0;
		listData();
    }
    
}
//table鼠标悬停换色
function mouse(){
// 如果鼠标移到行上时，执行函数
	$(".table tr").mouseover(function() {
		$(this).css({background : "#CDDAEB"});
		$(this).find("td").each(function(index, ele){
			$(ele).css({color: "#1D1E21"});
		});
	}).mouseout(function() {
		$(this).css({background : "#FFF"});
		$(this).find("td").each(function(index, ele){
			$(ele).css({color: "#909090"});
		});
	});
}
